package exam;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Tests the answer to the second map question.
 * The text of the question is as follows:
 * "Write a method that searches through an email database stored as a Map<String, Student> and 
 *  returns a Set<String> of emails for those who have taken more than the number of credits given 
 *  in the parameter."
 * 
 * @author Branden Ogata
 *
 */

public class TestMapA01 extends Tester
{
  public static void main(String[] args)
  {
    final double POINTS = getPoints(args);
    
    MapA01 question = new MapA01();
    
    Student ics0 = new Student("Paul E. Gone", "ICS", 128);
    Student ics1 = new Student("Al Arm", "ICS", 64);
    Student ics2 = new Student("Al B. Back", "ICS", 8); // in 2^x and Fibonacci sequence
    Student non0 = new Student("Ira Fuse", "Chemistry", 4); // C4
    Student non1 = new Student("Dewey Havtoo", "LIS", 23); // current version of Dewey Decimal Sys
    Student non2 = new Student("Sandy Beech", "Oceanography", 18); // appx. molar mass of water
    Student non3 = new Student("Toby R. Notabee", "English", 37); // number of Shakespeare plays
    Student non4 = new Student("Luke Out", "Opthamology", 2); // two eyes
    Student non5 = new Student("Robin Banks", "Political Science", 535); // 535 in Congress
    Student non6 = new Student("Hugh Blewitt", "Political Science", 15); // 15 Cabinet members
    Student non7 = new Student("Millie Meter", "Chemistry", 1000); // 1000 mm in 1 m
    Student non8 = new Student("Marcus Absent", "Math", 227); // pi in ASCII decimal values    
    
    Map<String, Student> database = new HashMap<String, Student>();
    database.put("pgone@hawaii.edu", ics0);
    database.put("alarm@hawaii.edu", ics1);
    database.put("albback@hawaii.edu", ics2); 
    database.put("irafuse@hawaii.edu", non0);
    database.put("deweyhavtoo@hawaii.edu", non1); 
    database.put("sbeech@hawaii.edu", non2); 
    database.put("trnotabe@hawaii.edu", non3); 
    database.put("lukeout@hawaii.edu", non4); 
    database.put("robinbanks@hawaii.edu", non5); 
    database.put("hblewitt@hawaii.edu", non6); 
    database.put("milmeter@hawaii.edu", non7); 
    database.put("mabsent@hawaii.edu", non8); 
    
    Set<String> answers = new HashSet<String>();
    
    answers.add("pgone@hawaii.edu");
    answers.add("alarm@hawaii.edu");
    answers.add("albback@hawaii.edu"); 
    answers.add("irafuse@hawaii.edu");
    answers.add("deweyhavtoo@hawaii.edu"); 
    answers.add("sbeech@hawaii.edu"); 
    answers.add("trnotabe@hawaii.edu"); 
    answers.add("lukeout@hawaii.edu"); 
    answers.add("robinbanks@hawaii.edu"); 
    answers.add("hblewitt@hawaii.edu"); 
    answers.add("milmeter@hawaii.edu"); 
    answers.add("mabsent@hawaii.edu"); 
    System.out.println(test(Category.EQUALS, "findByCredits(database, -1)", 
                            answers, question.findByCredits(database, -1), 
                            percentageToPoints(FIFTH, POINTS)));

    answers.remove("lukeout@hawaii.edu");
    System.out.println(test(Category.EQUALS, "findByCredits(database, 2)", 
                            answers, question.findByCredits(database, 2), 
                            percentageToPoints(FIFTH, POINTS)));

    answers.remove("albback@hawaii.edu");
    answers.remove("irafuse@hawaii.edu");
    answers.remove("deweyhavtoo@hawaii.edu"); 
    answers.remove("sbeech@hawaii.edu");
    answers.remove("hblewitt@hawaii.edu"); 
    System.out.println(test(Category.EQUALS, "findByCredits(database, 36)", 
                            answers, question.findByCredits(database, 36), 
                            percentageToPoints(FIFTH, POINTS)));
    
    answers.remove("alarm@hawaii.edu");
    answers.remove("trnotabe@hawaii.edu");
    System.out.println(test(Category.EQUALS, "findByCredits(database, 65)", 
                            answers, question.findByCredits(database, 65), 
                            percentageToPoints(FIFTH, POINTS)));        

    answers.clear();
    System.out.println(test(Category.EQUALS, "findByCredits(database, 65536)", 
                            answers, question.findByCredits(database, 65536), 
                            percentageToPoints(FIFTH, POINTS)));
    
    System.out.format("[%.2f/%.2f]%n", getTotalPoints(), POINTS);
  }
}
